<?php

namespace app\common\cachemodel\chakra;

use app\common\model\BaseCache;
use think\Log;
use XznsTools\cache\CacheManage;

class ChakraMiniappUser extends BaseCache
{
    private const LOG_PRE = '脉轮 小程序MiniAppUser Model 异常：';

    protected $table = 'wechat_backup_07_18_14_43_00.chakra_miniapp_user';

    // protected $cacheModel = 'chakra.miniapp_user';
    protected $cacheIdKey = 'id';

    /**
     * 添加小程序用户
     * @param $map
     * @return int|string
     */
    public function SavaData($map)
    {
        try
        {
            $id = $this->insertGetId($map);
        }
        catch (\Exception $e)
        {
            Log::write(self::LOG_PRE . $e->getMessage() . '失败行数：' . $e->getLine(), 'error');
            $id = 0;
        }

        return $id;
    }

    /**
     * 通过 小程序类型 获取存入的唯一id类型
     * @param $mini_type
     * @return int $type 1=>$id,2=>unionid,3=>$openid;
     */
    public function getTypeFromMiniType($mini_type): int
    {
        $type = 0;
        switch ($mini_type)
        {
            case 'TT':
            case 'ALIPAY':
                $type = 3;
                break;
            case 'SWAN':
            case 'WEAPP':
            case 'QQ':
                $type = 2;
                break;
        }
        return $type;
    }
}